package com.txzn.common.use;

import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.txzn.common.config.common.config.EnumMsg;
import com.txzn.common.model.IntroduceTime;

/**
 * 用户使用页面的相关接口
 * @author hadoop
 *
 */
public class UseController extends Controller {
	
	
	public class Urlpra{
		public static final String index="index.html";
		public static final String timing="timing.html";
		public static final String select="select.html";
		public static final String questions="questions.html";
		public static final String edit="edit.html";
		public static final String add="add.html";
	}
	
	/**
	 * 首页
	 */
	public void index(){
		render(Urlpra.index);
	}
	/**
	 * 计时页
	 */
	public void timing(){
		int questionid = getParaToInt() == null ? 0 : getParaToInt();
		setAttr("questionid", questionid);
		render(Urlpra.timing);
	}
	/**
	 * 选题页
	 */
	public void select(){
		int tid = getParaToInt() == null ? 0 : getParaToInt();
		setAttr("tid", tid);
		render(Urlpra.select);
	}
	/**
	 * 试题列表
	 */
	public void questions(){
		
		render(Urlpra.questions);
	}
	/**
	 * 修改试题
	 */
	public void edit(){
		
		render(Urlpra.edit);
	}
	/**
	 * 新增试题
	 */
	public void add(){
		
		render(Urlpra.add);
	}
	/**
	 * 试题导入
	 */
	public void explort(){
		// TODO 后期添加
	}
	
	/*******************************************************************************************************************************************************
	 * IntroduceTime
	 * 
	 * ********************************************************************************************************************************************************/
	
	/**
	 * 保存介绍所用时间
	 */
	public void saveIntroduceTime(){
		
		IntroduceTime it = new IntroduceTime();
		
		it.setUseTime(getPara("time",null));
		
		Ret ret = new Ret();
		
		boolean flag = it.save();
		
		if(flag){
			ret = Ret.ok().set("obj",it).set("msg", EnumMsg.success.getValue());
		}else{
			ret = Ret.fail().set("obj",it).set("msg", EnumMsg.fail.getValue());;
		}
		renderJson(ret);
	}
	/**
	 * 介绍的时间关联试题
	 */
	public void updIntroduceQid(){
		int qid = getParaToInt("qid"),tid = getParaToInt("tid");
		
		boolean flag = false;
		
		IntroduceTime it = IntroduceTime.dao.findById(tid);
		
		if(it != null){
			it.setQid(qid);
			flag = it.update();
		}
		
		Ret ret = new Ret();
		
		if(flag){
			ret = Ret.ok().set("obj",it).set("msg", EnumMsg.success.getValue());
		}else{
			ret = Ret.fail().set("obj",it).set("msg", EnumMsg.fail.getValue());;
		}
		renderJson(ret);
		
	}
	

	
}
